<template>
	<view class="x-wrapper">
		<view class="x-main-content">
			<u-navbar title="医院、医生搜索" :fixed="true" leftIconColor="#000" leftIconSize="42rpx" autoBack placeholder bgColor='#fff'>
			</u-navbar>
			<view class="top-bar">
				<search @toSearch="toSearch"></search>
				<view class="navs-box">
					<u-tabs :list="tabs" keyName="label" lineColor="#386FFF" lineHeight="6rpx"
						:inactiveStyle="searchInactiveStyle" :activeStyle="searchActiveStyle"
						:itemStyle="searchTabItemStyle" :current="current" :scrollable="false" @click="tabsClick">
					</u-tabs>
				</view>
			</view>
			<view class="mainPadding" :style="{'paddingTop':current == 1 ? '20px' : ''}">
				<view class="classifyWrap" v-if="current == 0">
					<view class="administrator" v-for="(item,index) in showHospList" :key="index">
						<view class="aaa" @click="goDetailFn(item)">
							<image :src="item.logo" mode=""></image>
							<view class="information">
								<text class="yiyuan">{{item.name}}</text>
								<view class="little">
									<text>{{item.level}}</text>
									<text class="marginright">丨</text>
									<text class="marginright">{{item.nature}}</text>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="list-box" style="margin-top: 200rpx;" v-if="current == 1">
					<template v-if="showListDoctor && showListDoctor.length">
						<doctor-item v-for="(item, index) in showListDoctor" :key="item.id" :item="item"></doctor-item>
					</template>
					<view class="x-no-data" v-if="showListDoctor.length === 0">
						<u-empty text="暂无数据" mode="data" marginTop="100"></u-empty>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import search from '@/components/search.vue'
	import doctorItem from "@/components/doctor/index";
	export default {
		components: {
			search,
			doctorItem
		},
		data() {
			return {
				params: {
					cityCode: '',
					name: '',
					pageNum: 1,
					pageSize: 20
				},
				showFlag: false,
				current: 0,
				id: 1,
				keyword:'',
				tabs: [
					{
						label: '医院',
						value: 1
					},
					{
						label: '医生',
						value: 2
					}
				],
				showHospList:[],
				showListDoctor:[]
			}
		},
		computed: {
		},
		onShow() {
		},
		created() {
			this.getHospitalData()
		},
		onHide() {

		},
		methods: {
			goDetailFn(item){
				uni.navigateTo({
					url: '/pages/hospital/hospitalDetail?id=' + item.id
				});
			},
			async getHospitalData() {
				let data = {
					cityCode: uni.getStorageSync('myAddress').cityId,
					name:this.keyword,
					// type:this.id,
					pageNum:1,
					pageSize:20
				}
				uni.showLoading({
					title: "加载中..."
				})
				let res = await this.$request('/api/index/getAllHospitalList', data, 'GET')
				uni.hideLoading();
				console.log(res)
				if(this.id == 1){
					this.$nextTick(()=>{
						this.showHospList = res.data.rows
					})
				}
				if(this.id == 2){
					this.$nextTick(()=>{
						this.showListDoctor = res.data.list
					})
				}
			},
			async getFamousDoctorList() {
				let data = {
					cityCode: uni.getStorageSync('myAddress').cityId,
					doctorName:this.keyword,
					// type:this.id,
					pageNum:1,
					pageSize:20
				}
				uni.showLoading({
					title: "加载中..."
				})
				let res = await this.$request('/api/index/getFamousDoctorList', data, 'GET')
				uni.hideLoading();
				console.log(res)
				if(this.id == 1){
					this.$nextTick(()=>{
						this.showHospList = res.data.list
					})
				}
				if(this.id == 2){
					this.$nextTick(()=>{
						this.showListDoctor = res.data.rows
					})
				}
			},
			tabsClick(e) {
				console.log('e',e)
				this.current = e.index
				this.id = e.value
				if(this.id == 1){
					this.getHospitalData()
				}else {
					this.getFamousDoctorList()
				}

			},
			toSearch(ctx) {
				this.keyword = ctx
				if(this.id == 1){
					this.getHospitalData()
				}else {
					this.getFamousDoctorList()
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.navs-box {
		padding: 10rpx;
		background: #fff;
	}

	.mainPadding {
		padding-top: 220rpx;
		padding-left: 38rpx;
		padding-right: 38rpx;
		box-sizing: border-box;
		padding-bottom: calc(100rpx + env(safe-area-inset-bottom));
	}

	/deep/.u-tabs__wrapper__nav__item {
		height: 88rpx !important;
	}

	.top-bar {
		position: fixed;
		width: 100%;
		z-index: 9999;
	}
	.classifyWrap {
		padding-bottom: 30rpx;
	}

	.administrator {
		display: flex;
		align-items: center;
		justify-content: space-between;
		background-color: #ffffff;
		height: 80px;
		margin-top: 10px;
		border-radius: 9px;
		padding: 19rpx;

		image {
			width: 142rpx;
			height: 142rpx;
		}

		.aaa {
			display: flex;
		}

		.information {
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			padding: 16rpx 0;
			margin-left: 28rpx;
			min-width: 0;

			.yiyuan {
				font-size: 32rpx;
				font-family: PingFangSC-Semibold, PingFang SC;
				font-weight: 600;
				color: #333333;
				letter-spacing: 2px;
				width: 400rpx;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
			}

			.little {
				font-size: 26rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				color: #6F7DA2;
				height: 40rpx;
				line-height: 40rpx;
			}
		}
	}
</style>